package com.mes.check.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.mes.common.domain.BasicModel;
import com.mes.task.domain.OperationTask;
import com.mes.task.domain.Task;
import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.basicdata.domain.WorkCenter;

/**
 * <p>
 * 检验任务，所有类型检验任务的父类
 * </p>
 */
@Entity()
@Table(name = "M_CHECKTASKS")
public class CheckTask extends BasicModel implements java.io.Serializable {
	public final static String CHECKTASKTYPE_FIRSTCHECK = "21"; // 强制修改零件任务优先级
	public final static String CHECKTASKTYPE_SECONDCHECK = "22"; // 强制修改零件任务优先级
	public final static String CHECKTASKTYPE_THIRDCHECK = "23"; // 强制修改零件任务优先级
	public final static String CHECKTASKTYPE_SUMMARYCHECK = "32"; // 汇总检验，几道工序一起的汇总
	public final static String CHECKTASKTYPE_OPERATIONCHECK = "33"; // 工序完工检验，流动检验
	public final static String CHECKTASKTYPE_REWORKCHECK = "34"; // 返工检验

	public final static int CHECKTASKSTATE_DRAG = 201; // 草稿
	public final static int CHECKTASKSTATE_NOTREADY = 204; // 未就绪
	public final static int CHECKTASKSTATE_READY = 205; // 已就绪或者已收料
	public final static int CHECKTASKSTATE_DISPATCHED = 206; // 已派工
	public final static int CHECKTASKSTATE_STARTED = 207; // 已开始
	public final static int CHECKTASKSTATE_COMPLETED = 209; // 已完成
	public final static int CHECKTASKSTATE_CANCELED = 210; // 已取消

	// 检验任务唯一号
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUEID")
	protected String uniqueId;

	// 检验任务编号，暂时未使用
	@Column(name = "CHECKTASKID")
	protected String checkTaskId;

	// 特性数
	@Column(name = "KEYCOUNT")
	protected Integer keyCount;

	// 检验使用的工作中心唯一号
	@Column(name = "CHECK_WORKCENTER_UID")
	protected String checkWorkCenterUid;
	@Transient
	protected WorkCenter checkWorkCenter;

	// 检验任务关联的工序任务唯一号
	@Column(name = "TASKUID")
	protected String taskUid;
	
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected Task task;
	
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected OperationTask operationTask;
		

	@Column(name = "CHECKTASKTYPE")
	protected String checkTaskType;

	@Column(name = "CHECKER")
	protected String checkerUid;
	@Transient
	protected Employee checker;

	@Column(name = "CHECKTASKSTATE")
	protected Integer checkTaskState;

	@Column(name = "DEPTID")
	protected String deptUid;
	@Transient
	protected Dept dept;

	@Column(name = "MASTERSHOP")
	protected String checkDeptUid;
	@Transient
	protected Dept checkDept;

	@Column(name = "PLANSTART")
	protected Date planStart;

	@Column(name = "PLANFINISH")
	protected Date planFinish;

	@Column(name = "ACTUALSTART")
	protected Date actualStart;

	@Column(name = "ACTUALFINISH")
	protected Date actualFinish;

	@Column(name = "PLANQTY")
	protected Float planQty;

	@Column(name = "COMPLETEQTY")
	protected Float completeQty;

	@Column(name = "DISPATCHGRADE")
	protected Integer dispatchGrade;

	@Column(name = "EARLYSTART")
	protected Date earlyStart;

	@Column(name = "LATEFINISH")
	protected Date lateFinish;
	/*
	 * 计划送料时间
	 */
	@Column(name = "PLANSEND")
	protected Date planSend;
	/**
	 * 实际送料时间
	 */
	@Column(name = "ACTUALSEND")
	protected Date actualSend;
	/**
	 * 送料数量
	 */
	@Column(name = "COMITQTY")
	protected Float sendQty;
	/**
	 * 送料人
	 */
	@Column(name = "SENDER")
	protected String senderUid;
	@Transient
	protected Employee sender;

	@Column(name = "SUSPENDED")
	protected Boolean isSuspended;
	/**
	 * 是否设备在停机等待
	 */
	@Column(name = "DEVICE_PAUSE")
	protected Boolean isDevicePause;

	/**
	 * 检验室收到物料数量
	 */
//	@Formula("(select sum(i.invqty) from i_invmanage i "
//			+ "inner join i_warebin b on i.warehouseid = b.warehouseid and i.binid = b.binid "
//			+ "where i.part_number = (select t.part_number from t_tasks t where t.taskuid=TASKUID) "
//			+ "and i.batchnum = (select t.batchnum from t_tasks t where t.taskuid=TASKUID) "
//			+ "and b.deptid = MASTERSHOP)")
	@Transient
	protected Float receivedQty;
	
	
	
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uniqueId;
	}

	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.uniqueId = uuid;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getCheckTaskId() {
		return checkTaskId;
	}

	public void setCheckTaskId(String checkTaskId) {
		this.checkTaskId = checkTaskId;
	}

	public Integer getKeyCount() {
		return keyCount;
	}

	public void setKeyCount(Integer keyCount) {
		this.keyCount = keyCount;
	}

	public String getCheckWorkCenterUid() {
		return checkWorkCenterUid;
	}

	public void setCheckWorkCenterUid(String checkWorkCenterUid) {
		this.checkWorkCenterUid = checkWorkCenterUid;
	}

	public WorkCenter getCheckWorkCenter() {
		return checkWorkCenter;
	}

	public void setCheckWorkCenter(WorkCenter checkWorkCenter) {
		this.checkWorkCenter = checkWorkCenter;
	}

	public String getTaskUid() {
		return taskUid;
	}

	public void setTaskUid(String taskUid) {
		this.taskUid = taskUid;
	}

	public OperationTask getOperationTask() {
		return operationTask;
	}

	public void setOperationTask(OperationTask operationTask) {
		this.operationTask = operationTask;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public String getCheckTaskType() {
		return checkTaskType;
	}

	public void setCheckTaskType(String checkTaskType) {
		this.checkTaskType = checkTaskType;
	}

	public String getCheckerUid() {
		return checkerUid;
	}

	public void setCheckerUid(String checkerUid) {
		this.checkerUid = checkerUid;
	}

	public Employee getChecker() {
		return checker;
	}

	public void setChecker(Employee checker) {
		this.checker = checker;
	}

	public Integer getCheckTaskState() {
		return checkTaskState;
	}

	public void setCheckTaskState(Integer checkTaskState) {
		this.checkTaskState = checkTaskState;
	}

	public String getDeptUid() {
		return deptUid;
	}

	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public String getCheckDeptUid() {
		return checkDeptUid;
	}

	public void setCheckDeptUid(String checkDeptUid) {
		this.checkDeptUid = checkDeptUid;
	}

	public Dept getCheckDept() {
		return checkDept;
	}

	public void setCheckDept(Dept checkDept) {
		this.checkDept = checkDept;
	}

	public Date getPlanStart() {
		return planStart;
	}

	public void setPlanStart(Date planStart) {
		this.planStart = planStart;
	}

	public Date getPlanFinish() {
		return planFinish;
	}

	public void setPlanFinish(Date planFinish) {
		this.planFinish = planFinish;
	}

	public Date getActualStart() {
		return actualStart;
	}

	public void setActualStart(Date actualStart) {
		this.actualStart = actualStart;
	}

	public Date getActualFinish() {
		return actualFinish;
	}

	public void setActualFinish(Date actualFinish) {
		this.actualFinish = actualFinish;
	}

	public Float getPlanQty() {
		return planQty;
	}

	public void setPlanQty(Float planQty) {
		this.planQty = planQty;
	}

	public Float getCompleteQty() {
		return completeQty;
	}

	public void setCompleteQty(Float completeQty) {
		this.completeQty = completeQty;
	}

	public Integer getDispatchGrade() {
		return dispatchGrade;
	}

	public void setDispatchGrade(Integer dispatchGrade) {
		this.dispatchGrade = dispatchGrade;
	}

	public Date getEarlyStart() {
		return earlyStart;
	}

	public void setEarlyStart(Date earlyStart) {
		this.earlyStart = earlyStart;
	}

	public Date getLateFinish() {
		return lateFinish;
	}

	public void setLateFinish(Date lateFinish) {
		this.lateFinish = lateFinish;
	}

	public Date getPlanSend() {
		return planSend;
	}

	public void setPlanSend(Date planSend) {
		this.planSend = planSend;
	}

	public Date getActualSend() {
		return actualSend;
	}

	public void setActualSend(Date actualSend) {
		this.actualSend = actualSend;
	}

	public Float getSendQty() {
		return sendQty;
	}

	public void setSendQty(Float sendQty) {
		this.sendQty = sendQty;
	}

	public String getSenderUid() {
		return senderUid;
	}

	public void setSenderUid(String senderUid) {
		this.senderUid = senderUid;
	}

	public Employee getSender() {
		return sender;
	}

	public void setSender(Employee sender) {
		this.sender = sender;
	}

	public Boolean getIsSuspended() {
		return isSuspended;
	}

	public void setIsSuspended(Boolean isSuspended) {
		this.isSuspended = isSuspended;
	}

	public Boolean getIsDevicePause() {
		return isDevicePause;
	}

	public void setIsDevicePause(Boolean isDevicePause) {
		this.isDevicePause = isDevicePause;
	}

	public Float getReceivedQty() {
		return receivedQty;
	}

	public void setReceivedQty(Float receivedQty) {
		this.receivedQty = receivedQty;
	}

}
